// PhprpcServlet.java
/**
 * 簡易 PHPRPC in Servlet 範例
 */
package com.studylazy.phprpc;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.phprpc.PHPRPC_Server;

public class PhprpcServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) 
	throws ServletException, IOException {
		PHPRPC_Server phprpc_server = new PHPRPC_Server();

		// 宣告要發布的方法
		phprpc_server.add("get", PhprpcServlet.class);
		phprpc_server.add("set", PhprpcServlet.class);

		// 啟動 phprpc server
		phprpc_server.start(request, response);
		super.service(request, response);
	}

	/**
	 * 無參數, 直接回應 "Hello"
	 */
	public static String get() {
		return "Hello";
	}

	/**
	 * @param msg
	 *            直接回應參數:msg 的內容
	 */
	public static String set(String msg) {
		return msg;
	}
}